package com.demo.springcloud.controller;

import com.demo.springcloud.entities.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Controller
public class DeptConsumerController {

//	private static String REST_URL_PREFIX = "http://localhost:8081";
	private static String REST_URL_PREFIX = "http://DEMP-PRODUCER";

	@Autowired
	private RestTemplate restTemplate;

	@ResponseBody
	@RequestMapping(value = "/consumer/get/{id}", method = RequestMethod.GET)
	public Dept findById(@PathVariable("id") Long id){
		return restTemplate.getForObject(REST_URL_PREFIX+"/demo/get/1", Dept.class, id);
	}

	@ResponseBody
	@RequestMapping(value = "/consumer/list")
	public List<Dept> findDeptList(){
		return restTemplate.getForObject(REST_URL_PREFIX+"/demo/list", List.class);
	}

}
